package com.dingdang.controller.car_detail_management;


import com.dingdang.data.Result;
import com.dingdang.em.ResultEnum;
import com.dingdang.entity.BrandSeries;
import com.dingdang.mapper.BrandSeriesMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("brandSeries")
@Api("品牌系列接口")
public class BrandSeriesController
{
    @Autowired
    private BrandSeriesMapper brandSeriesMapper;

    @GetMapping
    @ApiOperation("品牌系列搜索")
    @ApiImplicitParam(name = "void",value = "空",required = true,paramType = "query")
    public Result getCarGoods()
    {
        List<BrandSeries> brandSeriesList = brandSeriesMapper.selectList(null);
        return Result.response(ResultEnum.SUCCESS).setData(brandSeriesList);
    }

    //管理员增加
    @PostMapping
    @ApiOperation("品牌系列增加")
    @ApiImplicitParam(name = "TbCarGoods",value = "品牌系列实体类",required = true,paramType = "body")
    public Result insertAdmin(@RequestBody BrandSeries brandSeries)
    {
        int i = brandSeriesMapper.insert(brandSeries);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }

    //管理员回显
    @PostMapping("/toUpdate")
    @ApiOperation("品牌系列回显")
    @ApiImplicitParam(name = "id",value = "品牌系列id",required = true,paramType = "query")
    public Result ToUpdateAdmin(@RequestParam("id") Long id)
    {
        BrandSeries brandSeries = brandSeriesMapper.selectById(id);
        return Result.response(ResultEnum.SUCCESS).setData(brandSeries);
    }

    //管理员修改
    @PutMapping
    @ApiOperation("品牌系列修改")
    @ApiImplicitParam(name = "BrandSeries",value = "品牌系列实体类",required = true,paramType = "body")
    public Result UpdateAdmin(@RequestBody BrandSeries brandSeries)
    {
        int i = brandSeriesMapper.updateById(brandSeries);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }

    @DeleteMapping()
    @ApiOperation("品牌系列删除")
    @ApiImplicitParam(name = "id",value = "品牌系列id",required = true,paramType = "query")
    public Result deleteInfo(@RequestParam(value = "id") Long []ids)
    {
        List<Long> deleteBatch = new ArrayList<>();
        for (Long addr:ids)
        {
            deleteBatch.add(addr);
        }
        int i = brandSeriesMapper.deleteBatchIds(deleteBatch);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }
}
